<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>复杂请求</title>
</head>
<body>
  <button id="btn">发请求</button>

  <script>
    let btn = document.getElementById('btn')
    btn.addEventListener('click', () => {
      let xhr = new XMLHttpRequest()
      document.cookie = 'name=wn'
      xhr.withCredentials = true
      xhr.open('put', 'http://localhost:3000/getData', true)  // app1
      xhr.setRequestHeader('name', 'wn')
      xhr.onreadystatechange = function() {
        if (xhr.readyStatus === 4  && xhr.status === 200) {
          console.log(xhr.response);
        }
      }
      xhr.send()  // 请求发送
    })
  </script>
</body>
</html>